/**
 *  *2010-7-30 上午12:50:29  add 
 */
package com.base.myproject.client.quickinput;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;

/**
 * @author Administrator
 *2010-7-30
 * javazgw@gmail.com
 */
public class QuickInputContainer {

	ArrayList<QuickInputItem> inputlist = new ArrayList<QuickInputItem> ();
	static QuickInputContainer qic= null;
	private  QuickInputContainer()
	{
		
	}
	
	public static QuickInputContainer getInstance()
	{
		long t1 = java.lang.System.currentTimeMillis();
		
		if(qic==null)
			qic = new QuickInputContainer();
		long t2 = java.lang.System.currentTimeMillis();
		//GWT.log("inittime = "+(t2-t1));
		return qic;
	}
	
	public void add(QuickInputItem qi)
	{
		if(inputlist.size()>20)
			inputlist.remove(0);
		inputlist.add(qi);
		
		
	}
	public void add(int keycode,long t)
	{
		QuickInputItem qi = new QuickInputItem(keycode,t);
		add(qi);
	}
	public void clear()
	{
		inputlist.clear();
	}
	public String getQuickInputStr()
	{
		String str="";
		long t1=0;
		long t2=0;
		long tempt=0;
		/*int i=0;
		for(QuickInputItem pi:inputlist)
		{
			if(i==0)
			{
				t1 = pi.getT();
			}
			t2 = pi.getT();
			
			
			
			if(pi.getT()<1000)
				str+=pi.getKeyCode()+"-";0002635192
				
		}
		*/
		for(int i=inputlist.size()-1;i>=0;i--)
		{
			if(i>0)
			{
				tempt = inputlist.get(i).getT() - inputlist.get(i-1).getT();
				
			
			}
			if(i==0)
				tempt=0;
			
				GWT.log("tempt"+tempt+" code = "+(char)(inputlist.get(i).getKeyCode())+" keycode="+(inputlist.get(i).getKeyCode()));
				
				
			if(tempt<500)
				str+=(char)(inputlist.get(i).getKeyCode())+"";
			else
			{
				
				break;
			}
		}
		clear();
		return str;
	}
}
